package com.fr.web.core.chwriter;

import com.fr.base.CodeUtils;
import com.fr.base.ColumnRow;
import com.fr.base.FRContext;
import com.fr.base.Painter;
import com.fr.base.Style;
import com.fr.base.core.html.Html;
import com.fr.base.core.html.Tag;
import com.fr.base.core.html.TextHtml;
import com.fr.base.core.json.JSONException;
import com.fr.data.core.db.BinaryObject;
import com.fr.report.CellElement;
import com.fr.report.ReportGetter;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.PaintUtils;
import com.fr.report.io.core.IOHelper;
import com.fr.util.Utils;
import com.fr.web.Repository;
import com.fr.web.core.HTMLWriterUtils;
import com.fr.web.core.ReportBackgroundDimension;
import java.awt.Image;
import java.awt.Rectangle;
import java.sql.Blob;
import java.sql.Clob;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PageCellWriter extends TreeCellWriter
{
  protected boolean isPrint = false;

  public PageCellWriter(Repository paramRepository, int paramInt, boolean paramBoolean)
  {
    super(paramRepository, paramInt);
    this.isPrint = paramBoolean;
  }

  public Tag cell2Tag(CellElement paramCellElement, ReportGetter paramReportGetter, Rectangle paramRectangle1, Rectangle paramRectangle2)
  {
    Tag localTag1 = null;
    try
    {
      localTag1 = super.cell2Tag(paramCellElement, paramReportGetter, paramRectangle1, paramRectangle2);
    }
    catch (JSONException localJSONException)
    {
      FRContext.getLogger().log(Level.WARNING, localJSONException.getMessage(), localJSONException);
    }
    this.resTag.attr("id", ColumnRow.valueOf(paramCellElement.getColumn(), paramCellElement.getRow()) + "-" + this.reportIndex + "-" + this.tableID);
    Style localStyle = paramCellElement.getStyle();
    if (((this.isPrint) && (!(this.cellGUIAttr.isPrintContent()))) || (this.cellHeight == 0))
      return this.resTag;
    if ((!(this.isPrint)) && (!(this.cellGUIAttr.isPreviewContent())))
    {
      HTMLWriterUtils.style_background2css(localStyle, this.resTag, this.cellGUIAttr, new ReportBackgroundDimension(this.cellWidth, this.cellHeight), this.repo);
      return this.resTag;
    }
    int i = this.cellHeight - (IOHelper.getBorderWidth(paramCellElement.getStyle().getBorderTop()) + IOHelper.getBorderWidth(paramCellElement.getStyle().getBorderBottom()) + 1) / 2;
    Tag localTag2 = localTag1;
    if (isHeavy())
    {
      localObject = new Tag("div").cls("fx").css("height", ((i > 0) ? i : 0) + "px");
      localTag1.sub((Html)localObject);
      localTag2 = new Tag("td").css("height", i + "px").css("width", this.cellWidth + "px");
      ((Tag)localObject).sub(new Tag("table").sub(new Tag("tbody").sub(new Tag("tr").sub(localTag2))));
    }
    Object localObject = paramCellElement.getValue();
    if (localObject instanceof Formula)
      localObject = dealWithValue4Formula(localObject);
    if ((this.isPrint) && (!(this.cellGUIAttr.isPrintZeroValue())) && (localObject != null) && (localObject.toString().matches("[\\-]?0[\\.]?[0]*")))
      localObject = null;
    if (localObject instanceof Blob)
      localObject = dealWithValue4Blob(localObject);
    if (localObject instanceof BinaryObject)
      localObject = dealBinaryObject(localObject);
    if (localObject instanceof Clob)
      localObject = dealClobValue(localObject);
    if ((!(this.isPrint)) && (dealWithTreeNodeButton(paramCellElement, localObject)))
      break label689:
    if ((localStyle.getVerticalText() == 1) || (localObject instanceof Painter) || (localObject instanceof Image) || (this.cellGUIAttr.isShowAsImage()))
    {
      HTMLWriterUtils.value2PaintableTag(localObject, paramCellElement.getStyle(), this.cellWidth, i, localTag2, this.repo, this.isPrint);
      localStyle = localStyle.derivePadding(0, 0);
    }
    else if (localObject != null)
    {
      if (this.cellGUIAttr.isShowAsHTML())
      {
        localTag2.sub(new TextHtml(Utils.objectToString(localObject)));
      }
      else
      {
        String str = PaintUtils.valueToText(localObject, paramCellElement.getStyle().getFormat());
        localStyle = PaintUtils.modCellStyleString(this.cellWidth, i, str, localStyle);
        localTag2.sub(new TextHtml(CodeUtils.htmlEncode(str)));
      }
    }
    if ((this.cellGUIAttr == null) || (this.cellGUIAttr.isPreviewBorder()))
      label689: HTMLWriterUtils.borderStyle2Css(localStyle, this.resTag);
    HTMLWriterUtils.style_noBorder_background2css(localStyle, (isHeavy()) ? localTag2 : this.resTag, this.cellGUIAttr, new ReportBackgroundDimension(this.cellWidth, this.cellHeight), this.repo);
    return ((Tag)this.resTag);
  }

  protected boolean dealWithTreeNodeButton(CellElement paramCellElement, Object paramObject)
  {
    return false;
  }

  protected Tag dealWithHyperlinkGroup(CellElement paramCellElement, Tag paramTag)
    throws JSONException
  {
    if (!(this.isPrint))
      return super.dealWithHyperlinkGroup(paramCellElement, paramTag);
    return paramTag;
  }
}